package com.slz3.business.module.wmsManagement.wmsWarehouseManage.repository;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.module.wmsManagement.wmsWarehouseManage.domain.WareTypeEnum;
import com.slz3.business.module.wmsManagement.wmsWarehouseManage.domain.WmsWarehouseManage;
import com.slz3.business.module.wmsManagement.wmsWarehouseManage.domain.WmsWarehouseManageEntity;
import org.springframework.data.domain.Example;

import java.util.List;
import java.util.stream.Collectors;

public class WmsWarehouseManageCustomizedRepositoryImpl implements WmsWarehouseManageCustomizedRepository {
    @Override
    public void test() {
        System.err.println(Repositorys.wmsWarehouseManage);
        System.err.println("test: customized repository");
    }

    @Override
    public List<WmsWarehouseManage> findHouseAndArea() {
        WmsWarehouseManage manage = new WmsWarehouseManage();
        manage.setValidFlag(ValidFlag.VALID);
        Example<WmsWarehouseManage> example = Example.of(manage);
        List<WmsWarehouseManage> manages = Repositorys.wmsWarehouseManage.findAll(example);
        List<WmsWarehouseManage> houses = manages.stream().filter(WareTypeEnum::isWmsHouse).collect(Collectors.toList());
        List<WmsWarehouseManage> areas = manages.stream().filter(WareTypeEnum::isWmsArea).collect(Collectors.toList());
        houses.forEach(m -> {
            List<WmsWarehouseManage> result = areas.stream().filter(item -> m.getUuid().equals(item.getUpper())).collect(Collectors.toList());
            m.setWmsAreas(result);
        });
        return houses;
    }
}
